package siga.visao;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;



public class verErros extends javax.swing.JDialog {
    static String Texto;

    public verErros(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        jtpErSis.setText(jtpErSis.getText()+"\n"+Texto);
    }

    public static void setErro(String txt){
       Texto = Texto+txt+"\n";
       send("mail.fucap.edu.br", "rafaelfrasson@gmail.com", "contato@fucap.edu.br", "Apresentação de Erros SIGA", txt);
    }

     public static void send(String smtpServer, String to, String from, String subject, String body){
        try{
          Properties props = System.getProperties();
          props.put("mailfucap.edu.br", smtpServer);
          Session session = Session.getDefaultInstance(props, null);
          Message msg = new MimeMessage(session);
          msg.setFrom(new InternetAddress(from));
          msg.setRecipients(Message.RecipientType.TO,
          InternetAddress.parse(to, false));
          msg.setSubject(subject);
          msg.setText(body);
          msg.setHeader("X-Mailer", "RAROSISTEMAS");
          msg.setSentDate(new Date());
          Transport.send(msg);
        }catch (Exception ex){
            setErro(ex.getMessage());
        }
  }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpERPrincipal = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtpErSis = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lista de Erros");

        jpERPrincipal.setName("jpERPrincipal"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtpErSis.setName("jtpErSis"); // NOI18N
        jScrollPane1.setViewportView(jtpErSis);

        javax.swing.GroupLayout jpERPrincipalLayout = new javax.swing.GroupLayout(jpERPrincipal);
        jpERPrincipal.setLayout(jpERPrincipalLayout);
        jpERPrincipalLayout.setHorizontalGroup(
            jpERPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
        );
        jpERPrincipalLayout.setVerticalGroup(
            jpERPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpERPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpERPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpERPrincipal;
    private javax.swing.JTextPane jtpErSis;
    // End of variables declaration//GEN-END:variables

}
